/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.fzhucc.modules.Love.controller;

import com.fzhucc.annotation.Log;
import com.fzhucc.modules.Love.dto.LoveDemandDto;
import com.fzhucc.modules.Love.dto.LoveModelDto;
import com.fzhucc.modules.Love.service.LoveService;
import com.fzhucc.modules.loveDemandRecord.domain.dto.LoveDemandRecordQueryCriteria;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author yyg
 * @date 2024-06-12
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "需求劳模收藏")
@RequestMapping("/api/love")
public class LoveController {

    private final LoveService loveService;


    @PostMapping(value = "/demand")
    @Log("需求收藏")
    @ApiOperation("需求收藏")
    public ResponseEntity<Object> createLoveDemandRecord(@RequestBody LoveDemandDto dto){
        return new ResponseEntity<>(loveService.createDemandLove(dto), HttpStatus.CREATED);
    }

    @PostMapping(value = "/model")
    @Log("劳模收藏")
    @ApiOperation("劳模收藏")
    public ResponseEntity<Object> createLoveModelRecord(@RequestBody LoveModelDto dto){
        return new ResponseEntity<>(loveService.createModelLove(dto), HttpStatus.CREATED);
    }

    @PostMapping(value = "/demandIsLove")
    @Log("判断此需求当前登录用户是否收藏")
    @ApiOperation("判断此需求当前登录用户是否收藏")
    public ResponseEntity<Object> DemandRecordIsLove(@RequestBody LoveDemandDto dto){
        return new ResponseEntity<>(loveService.demandRecordIsLove(dto), HttpStatus.OK);
    }

    @PostMapping(value = "/modelIsLove")
    @Log("判断此劳模当前登录用户是否收藏")
    @ApiOperation("判断此劳模当前登录用户是否收藏")
    public ResponseEntity<Object> ModelRecordIsLove(@RequestBody LoveModelDto dto){
        return new ResponseEntity<>(loveService.modelRecordIsLove(dto), HttpStatus.OK);
    }

    @DeleteMapping(value = "/cancelDemand")
    @Log("取消需求收藏")
    @ApiOperation("取消需求收藏")
    public ResponseEntity<Object> deleteLoveDemandRecord(@RequestBody LoveDemandDto dto) {
        loveService.deleteAllDemands(dto.getDemandId());
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @DeleteMapping(value = "/cancelModel")
    @Log("取消劳模收藏")
    @ApiOperation("取消劳模收藏")
    public ResponseEntity<Object> deleteLoveModelRecord(@RequestBody LoveModelDto dto) {
        loveService.deleteAllModel(dto.getModelId());
        return new ResponseEntity<>(HttpStatus.OK);
    }

}